package jmine.tec.report.cell.impl;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;

import jmine.tec.report.cell.DataCell;

/**
 * @author adalberto
 */
public class DateDataCell implements DataCell, Serializable {

    private static final long serialVersionUID = 1L;

    private final Date date;

    /**
     * Construtor
     * 
     * @param date Date
     */
    public DateDataCell(final Date date) {
        this.date = new Date(date.getTime());
    }

    /**
     * Retorna a data
     * 
     * @return Date
     */
    public Date toDate() {
        return new Date(this.date.getTime());

    }

    /**
     * Retorna not a number
     * 
     * @return Double
     */
    public Double toDouble() {
        return Double.NaN;
    }

    /**
     * Retorna o valor em forma de String sem formata��o.
     * 
     * @return String
     */
    @Override
    public String toString() {
        return this.date.toString();
    }

    /**
     * Retorna uma string da data no formato desejado
     * 
     * @param dateFormat DateFormat
     * @param doubleFormat NumberFormat
     * @param currencyFormat NumberFormat
     * @return String
     */
    public String toString(final DateFormat dateFormat, final NumberFormat doubleFormat,
            final NumberFormat currencyFormat) {

        if (dateFormat != null) {
            return dateFormat.format(this.date);
        } else {
            return this.date.toString();
        }

    }

    /**
     * Compara este DataCell � outro Retorna um inteiro menor, igual ou maior que zero se esta instancia for inferior, igual ou maior que o
     * parametro.
     * 
     * @param o DataCell
     * @return int
     */
    public int compareTo(final DataCell o) {
        return this.toDate().compareTo(o.toDate());
    }

    /**
     * @return int
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.date == null) ? 0 : this.date.hashCode());
        return result;
    }

    /**
     * @return boolean
     * @param obj {@link Object}
     */
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        final DateDataCell other = (DateDataCell) obj;
        if (this.date == null) {
            if (other.date != null) {
                return false;
            }
        } else if (!this.date.equals(other.date)) {
            return false;
        }
        return true;
    }
}
